package org.client.otdr.rest;

import java.util.Arrays;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.client.otdr.OTDRID;
import org.client.otdr.OtdrDomainService;
import org.openems.DoubleArray;
import org.openems.entity.TraceEntity;

import framework.DomainService;
import framework.Utility;
import framework.webserver.ServiceStore;

@Path("/otdrCurrentTrace")
public class OtdrCurrentTrace {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    public DoubleArray get(@QueryParam("length") String length) {
    	DomainService service = ServiceStore.get("OTDR");
    	TraceEntity e = (TraceEntity)service.getEntity(OTDRID.get().TRACE);
    	DoubleArray ret = new DoubleArray();
    	ret.data = Arrays.asList(Utility.lesser(e.getData(), Integer.valueOf(length)));
    	return ret;
    }
}
